Published 2006-11-24 15:02:00
wget http://www.akbkhome.com/svn/akpear/make_pearball.shStep 2) - Create an alternative bootstrapper. (eg. index.zh_HK.php)
#check and edit!
sh make_pearball.sh
cd /var/www/myproject
tar xvfz /var/www/pearball-*****.tgz
<?php2) Create a class to wrap the Translator tool: MyProject/Translator.php
// set up the include path to work! - our project, and our private pear install
ini_set('include_path',
realpath(dirname(__FILE__)) . ":"
. PATH_SEPARATOR . realpath(dirname(__FILE__)) . '/pear'
);
require_once 'HTML/FlexyFramework.php';
HTML_FlexyFramework::factory(array(
// all of these are available via PEAR::getStaticProperty('__section__','options')
'HTML_FlexyFramework' => array(
'project' => 'MyProject', // our project name
'use_cookies' => 1, // dont use phpsess url for sessoins
'file' => '.disabled', // dont load config from /ConfigData
// - that was an old way of doing things
'auth_class_file' => false, // dont try and load an authentication module.
),
'HTML_Template_Flexy' => array(
'locale' => 'zh_HK.UTF-8', // our locale
'Translation2' => array( // settings for Translation 2 constructor
'driver' => 'gettext', // we are using gettext driver.
'options' => array(
'prefetch' => false,
'langs_avail_file' => 'langs.ini', // these files are in this dir.
'domains_path_file' => 'domains.ini',
'default_domain' => 'myproject',
'file_type' => 'po',
)),
'compileDir' => ini_get('session.save_path') . '/myproject_zh_HK',
),
'Myproject' => array( // our project varoable
// put project options in here..
),
// set up the database connection + path to dataobjects.
'DB_DataObject' => array(
'database' => '.....', // fill in the correct details here!
'schema_location' => 'Myproject/DataObjects',
'class_location' => 'Myproject/DataObjects',
'require_prefix' => 'Myproject/DataObjects/',
'class_prefix' => 'Myproject_DataObjects_',
//'quote_identifiers' = 1
),
));
<?php
require_once 'HTML/Template/Flexy/Translator.php';
// you could extend the project class, to inherit authentication.
class MyProject_Translate extends HTML_FlexyFramework_Page
{
var $masterTemplate = 'master_translate.html';
function getAuth()
{
return true; // you may want to use the project authentication here
}
function start() // deals with get & post.
{
$flexyOpts = PEAR::getStaticProperty('HTML_Template_Flexy','options');
$t = new HTML_Template_Flexy_Translator(array(
'baseLang' => 'en',
'targetLangs' => array('zh_HK.UTF-8', 'zh_CN.UTF-8', 'ja_JP.UTF-8'),
'appURL' => $this->baseURL.'/Translate.html', // == this class is the action class
'Translation2' => $flexyOpts['Translation2'],
));
if ($e = $t->process($_GET, $_POST)) {
// display errors.. - a bit of a hack..
print_r($e);
}
$this->translator = $t;
}
function outputBody() {
$this->translator->outputDefaultTemplate();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Your Project Translator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
{outputBody():h}
</body>
</html>
myproject = ./localeNOTE: domains.ini needs to be writable on the server you edit the translation files.
[en]now see if visiting http://yourwebsite/myproject/index.php/Translate.html works....
name = English
encoding = iso-8859-1
[zh_HK.UTF-8]
name = Traditional Chinese
encoding = utf-8
;[zh_CN.UTF-8]
;name = Simplified Chinese
;encoding = utf-8
;[ja_JP.UTF-8]
;name = Japanese
;encoding = utf-8